/*     */ package com.cr.web.controller.system;
/*     */ 
/*     */ import com.cr.common.annotation.Log;
/*     */ import com.cr.common.core.controller.BaseController;
/*     */ import com.cr.common.core.domain.AjaxResult;
/*     */ import com.cr.common.core.domain.Ztree;
/*     */ import com.cr.common.core.domain.entity.SysMenu;
/*     */ import com.cr.common.core.domain.entity.SysRole;
/*     */ import com.cr.common.enums.BusinessType;
/*     */ import com.cr.common.utils.ShiroUtils;
/*     */ import com.cr.framework.shiro.util.AuthorizationUtils;
/*     */ import com.cr.system.service.ISysMenuService;
/*     */ import java.util.List;
/*     */ import org.apache.shiro.authz.annotation.RequiresPermissions;
/*     */ import org.springframework.beans.factory.annotation.Autowired;
/*     */ import org.springframework.stereotype.Controller;
/*     */ import org.springframework.ui.ModelMap;
/*     */ import org.springframework.validation.annotation.Validated;
/*     */ import org.springframework.web.bind.annotation.GetMapping;
/*     */ import org.springframework.web.bind.annotation.PathVariable;
/*     */ import org.springframework.web.bind.annotation.PostMapping;
/*     */ import org.springframework.web.bind.annotation.RequestMapping;
/*     */ import org.springframework.web.bind.annotation.ResponseBody;
/*     */ 
/*     */ @Controller
/*     */ @RequestMapping({"/system/menu"})
/*     */ public class SysMenuController extends BaseController {
/*  35 */   private String prefix = "system/menu";
/*     */   
/*     */   @Autowired
/*     */   private ISysMenuService menuService;
/*     */   
/*     */   @RequiresPermissions({"system:menu:view"})
/*     */   @GetMapping
/*     */   public String menu() {
/*  44 */     return this.prefix + "/menu";
/*     */   }
/*     */   
/*     */   @RequiresPermissions({"system:menu:list"})
/*     */   @PostMapping({"/list"})
/*     */   @ResponseBody
/*     */   public List<SysMenu> list(SysMenu menu) {
/*  52 */     Long userId = ShiroUtils.getUserId();
/*  53 */     List<SysMenu> menuList = this.menuService.selectMenuList(menu, userId);
/*  54 */     return menuList;
/*     */   }
/*     */   
/*     */   @Log(title = "菜单管理", businessType = BusinessType.DELETE)
/*     */   @RequiresPermissions({"system:menu:remove"})
/*     */   @GetMapping({"/remove/{menuId}"})
/*     */   @ResponseBody
/*     */   public AjaxResult remove(@PathVariable("menuId") Long menuId) {
/*  66 */     if (this.menuService.selectCountMenuByParentId(menuId) > 0)
/*  68 */       return AjaxResult.warn("存在子菜单,不允许删除"); 
/*  70 */     if (this.menuService.selectCountRoleMenuByMenuId(menuId) > 0)
/*  72 */       return AjaxResult.warn("菜单已分配,不允许删除"); 
/*  74 */     AuthorizationUtils.clearAllCachedAuthorizationInfo();
/*  75 */     return toAjax(this.menuService.deleteMenuById(menuId));
/*     */   }
/*     */   
/*     */   @GetMapping({"/add/{parentId}"})
/*     */   public String add(@PathVariable("parentId") Long parentId, ModelMap mmap) {
/*  84 */     SysMenu menu = null;
/*  85 */     if (0L != parentId.longValue()) {
/*  87 */       menu = this.menuService.selectMenuById(parentId);
/*     */     } else {
/*  91 */       menu = new SysMenu();
/*  92 */       menu.setMenuId(Long.valueOf(0L));
/*  93 */       menu.setMenuName("主目录");
/*     */     } 
/*  95 */     mmap.put("menu", menu);
/*  96 */     return this.prefix + "/add";
/*     */   }
/*     */   
/*     */   @Log(title = "菜单管理", businessType = BusinessType.INSERT)
/*     */   @RequiresPermissions({"system:menu:add"})
/*     */   @PostMapping({"/add"})
/*     */   @ResponseBody
/*     */   public AjaxResult addSave(@Validated SysMenu menu) {
/* 108 */     if ("1".equals(this.menuService.checkMenuNameUnique(menu)))
/* 110 */       return error("新增菜单'" + menu.getMenuName() + "'失败，菜单名称已存在"); 
/* 112 */     menu.setCreateBy(getLoginName());
/* 113 */     AuthorizationUtils.clearAllCachedAuthorizationInfo();
/* 114 */     return toAjax(this.menuService.insertMenu(menu));
/*     */   }
/*     */   
/*     */   @GetMapping({"/edit/{menuId}"})
/*     */   public String edit(@PathVariable("menuId") Long menuId, ModelMap mmap) {
/* 123 */     mmap.put("menu", this.menuService.selectMenuById(menuId));
/* 124 */     return this.prefix + "/edit";
/*     */   }
/*     */   
/*     */   @Log(title = "菜单管理", businessType = BusinessType.UPDATE)
/*     */   @RequiresPermissions({"system:menu:edit"})
/*     */   @PostMapping({"/edit"})
/*     */   @ResponseBody
/*     */   public AjaxResult editSave(@Validated SysMenu menu) {
/* 136 */     if ("1".equals(this.menuService.checkMenuNameUnique(menu)))
/* 138 */       return error("修改菜单'" + menu.getMenuName() + "'失败，菜单名称已存在"); 
/* 140 */     menu.setUpdateBy(getLoginName());
/* 141 */     AuthorizationUtils.clearAllCachedAuthorizationInfo();
/* 142 */     return toAjax(this.menuService.updateMenu(menu));
/*     */   }
/*     */   
/*     */   @GetMapping({"/icon"})
/*     */   public String icon() {
/* 151 */     return this.prefix + "/icon";
/*     */   }
/*     */   
/*     */   @PostMapping({"/checkMenuNameUnique"})
/*     */   @ResponseBody
/*     */   public String checkMenuNameUnique(SysMenu menu) {
/* 161 */     return this.menuService.checkMenuNameUnique(menu);
/*     */   }
/*     */   
/*     */   @GetMapping({"/roleMenuTreeData"})
/*     */   @ResponseBody
/*     */   public List<Ztree> roleMenuTreeData(SysRole role) {
/* 171 */     Long userId = ShiroUtils.getUserId();
/* 172 */     List<Ztree> ztrees = this.menuService.roleMenuTreeData(role, userId);
/* 173 */     return ztrees;
/*     */   }
/*     */   
/*     */   @GetMapping({"/menuTreeData"})
/*     */   @ResponseBody
/*     */   public List<Ztree> menuTreeData() {
/* 183 */     Long userId = ShiroUtils.getUserId();
/* 184 */     List<Ztree> ztrees = this.menuService.menuTreeData(userId);
/* 185 */     return ztrees;
/*     */   }
/*     */   
/*     */   @GetMapping({"/selectMenuTree/{menuId}"})
/*     */   public String selectMenuTree(@PathVariable("menuId") Long menuId, ModelMap mmap) {
/* 194 */     mmap.put("menu", this.menuService.selectMenuById(menuId));
/* 195 */     return this.prefix + "/tree";
/*     */   }
/*     */ }


/* Location:              D:\tmp\creditorRights-admin\BOOT-INF\classes\com.zip!\com\cr\web\controller\system\SysMenuController.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */